<?php

namespace app\admin\controller;

use app\Base;
use app\service\admin\VideoServices;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
use think\response\View;

/**
 * 视频管理
 *
 * user ：Du
 * Date : 2022/3/31
 * Time : 10:34
 * Class Video
 * @package projects\controller\admin
 */
class Video extends Base
{

    /***
     * 页面
     *
     * User : Du
     * Date : 2022/3/31
     * Time : 10:35
     * @return View
     */
    public function type(): View
    {
        return view('admin/video/type');
    }

    /**
     * 类型列表
     *
     * User : Du
     * Date : 2022/3/31
     * Time : 11:21
     * @param VideoServices $services
     * @return Json
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function typeList(VideoServices $services): Json
    {
        $res = $services::getList($this->params, 1);
        $this->res['data'] = $res['data'];
        $this->res['count'] = $res['count'];
        return $this->returnData();
    }

    /**
     * 添加类型
     *
     * User : Du
     * Date : 2022/3/31
     * Time : 11:38
     * @param VideoServices $services
     * @return Json
     */
    public function addType(VideoServices $services): Json
    {
        $res = $services::addData($this->params, 1);
        if (!$res) {
            return $this->returnData('addFail');
        }
        return $this->returnData();
    }

    /**
     * 视频页面
     *
     * User : Du
     * Date : 2022/3/31
     * Time : 11:54
     * @param VideoServices $services
     * @return View
     */
    public function index(VideoServices $services): View
    {
        $token = $services::getUploadToken();
        return view('admin/video/index', ['token' => $token]);
    }

    /**
     * 视频列表
     *
     * User : Du
     * Date : 2022/3/31
     * Time : 11:59
     * @param VideoServices $services
     * @return Json
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function dataList(VideoServices $services): Json
    {
        $res = $services::getList($this->params, 3);
        $this->res['data'] = $res['data'];
        $this->res['count'] = $res['count'];
        return $this->returnData();
    }
}